//
//  ConfirmPhoneView.m
//  OperationPro
//
//  Created by yaxue wang on 2017/1/6.
//  Copyright © 2017年 展鸿科技. All rights reserved.
//

#import "ConfirmPhoneView.h"

@interface ConfirmPhoneView()
@property (nonatomic, strong) NSString *title1;
@property (nonatomic, strong) NSString *title2;

@property (nonatomic, strong) void(^editPhone)(id);
@property (nonatomic, strong) void(^sendClick)(id);

@end
@implementation ConfirmPhoneView


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:[UIScreen mainScreen].bounds];
    if (self) {
        
    }
    return self;
}

+(ConfirmPhoneView *) showInputBox:(NSString *)title1 withName:(NSString *)title2 phoneAction:(editPhone)phoneAction sendAction:(sendClick)sendAction{
    ConfirmPhoneView *boxView = [[ConfirmPhoneView alloc] init];
    boxView.editPhone =phoneAction;
    boxView.sendClick=sendAction;
    boxView.title1=title1;
    boxView.title2=title2;
    [boxView showBox];
    return boxView;
}
- (void) showBox{
    [self initView];
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];
    
}
- (void) hideBox{
    [self removeFromSuperview];
}
- (void) initView{
    [self setBackgroundColor:[UIColor clearColor]];
    UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
    [self addSubview:bgView];
    [bgView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.5]];
    [bgView bk_whenTapped:^{
        [self hideBox];
    }];
    
    float width = self.frame.size.width -60;
    float height = 188;
    UIView* boxView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    [boxView setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:boxView];
    [boxView setCenter:self.center];
    [boxView.layer setCornerRadius:5];
    
    UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(15, 30, width-30, 30)];
    [boxView addSubview:lblTitle];
    lblTitle.text=@"报告将发送给以下联系人进行确认：";
    lblTitle.textColor=C(@"5a5a5a");
    [lblTitle setFont:F(14)];
    
    UILabel *phoneLab=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(lblTitle.frame)+5, width-30, 30)];
    phoneLab.text=self.title1;
    phoneLab.textColor=MainColor;
    [phoneLab setFont:F(14)];
    [boxView addSubview:phoneLab];
    
    UILabel *phoneLab2=[[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(phoneLab.frame)+5, width-15-60, 30)];
    phoneLab2.text=self.title2;
    phoneLab2.textColor=MainColor;
    [phoneLab2 setFont:F(14)];
    [boxView addSubview:phoneLab2];
    
    UILabel *editLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(phoneLab2.frame), CGRectGetMaxY(phoneLab.frame)+5,60, 30)];
    editLab.text=@"修改";
    editLab.textColor=MainColor;
    [editLab setFont:F(14)];
    [boxView addSubview:editLab];
    editLab.userInteractionEnabled=YES;
    
    [editLab bk_whenTapped:^{
        [self hideBox];
        if (self.editPhone) {
            self.editPhone(nil);
        }
    }];
    
    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    [boxView addSubview:button];
    button.frame=CGRectMake(15,CGRectGetMaxY(editLab.frame)+20, width-30, 40);
    [button setBackgroundColor:MainColor];
    button.layer.masksToBounds=YES;
    button.layer.cornerRadius=8;
    [button setTitle:@"发送" forState:UIControlStateNormal];
    [button bk_addEventHandler:^(id sender) {
        [self hideBox];
        if (self.sendClick) {
            self.sendClick(nil);
        }
    } forControlEvents:UIControlEventTouchUpInside];
    boxView.frame=CGRectMake((WindowWidth-width)/2, (WindowHeight-CGRectGetMaxY(button.frame)-20)/2, width, CGRectGetMaxY(button.frame)+30);
    
    
}

@end
